package org.example.myleet.p780;

public class Solution {
    public boolean reachingPoints(int sx, int sy, int tx, int ty) {
        if (sx > tx || sy > ty) {
            return false;
        }
        while (sx != tx || sy != ty) {
            if (tx < 0 || ty < 0) {
                break;
            }
            if (tx == 0 || ty == 0 || tx < sx || ty < sy) {
                break;
            }
            if (tx < ty) {
                int n = (ty - sy) / tx;
                if (n > 1) {
                    ty -= n * tx;
                } else {
                    ty -= tx;
                }
            } else {
                int n = (tx - sx) / ty;
                if (n > 1) {
                    tx -= n * ty;
                } else {
                    tx -= ty;
                }
            }
        }
        return sx == tx && sy == ty;
    }
}
